package com.example.quickthumb;




import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
	public static final String PREFS_NAME = "sampleGameSettings";		
	public static Typeface tf;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.main);
    
       tf = Typeface.createFromAsset(getAssets(),"data/fonts/floral.ttf");
       
       TextView tv = (TextView) findViewById(R.id.start);
       TextView tv1 = (TextView) findViewById(R.id.quick);
       TextView tv2 = (TextView) findViewById(R.id.settings);
       TextView tv3 = (TextView) findViewById(R.id.about);
       TextView tv4 = (TextView) findViewById(R.id.exit);
       if(tv==null)
    	   Log.d("null", "offf");
       tv.setTypeface(tf);
       
       tv1.setTypeface(tf);
       tv2.setTypeface(tf);
       tv3.setTypeface(tf);
       tv4.setTypeface(tf);
       
       tv.setOnTouchListener(new CustomTouchListener());
       tv1.setOnTouchListener(new CustomTouchListener());
       tv2.setOnTouchListener(new CustomTouchListener());
       tv3.setOnTouchListener(new CustomTouchListener());
       tv4.setOnTouchListener(new CustomTouchListener());
       
       tv.setOnClickListener(this);
       tv1.setOnClickListener(this);
       tv2.setOnClickListener(this);
       tv3.setOnClickListener(this);
       tv4.setOnClickListener(this);        
       
       Toast.makeText(this, "Press Menu to Start Game", Toast.LENGTH_LONG).show();
	
	getSettings();
	setDate();
		
	}
	private boolean[] settingsHolder = new boolean[5];

	private void getSettings() {
		SharedPreferences settings = getSharedPreferences(
				MainActivity.PREFS_NAME, 0);

		settingsHolder[0] = settings.getBoolean("sound", true);
		settingsHolder[1] = settings.getBoolean("music", true);
		settingsHolder[2] = settings.getBoolean("vibrate", true);
		settingsHolder[3] = settings.getBoolean("level1", true);
		settingsHolder[4] = settings.getBoolean("level2", true);

	}
	
	private void setDate(){
//		Global.soundEnabled=settingsHolder[0];
//		Global.vibertaeEnabled=settingsHolder[2];
//		if(!settingsHolder[3]&&!settingsHolder[4])
//			Global.currentLevel=Global.EASY;
//		else if(settingsHolder[3]&&!settingsHolder[4])
//			Global.currentLevel=Global.MEDIUM;
//		else
//			Global.currentLevel=Global.HARD;
			
		}
	
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	
	}

	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	
	@Override
	public void onClick(View v) {
		
		switch(v.getId()){
			case R.id.start:
//			startGame();
				Intent j = new Intent(this, LoadingActivity.class);
				j.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(j);
			
				break;
			
			case R.id.quick:
				
				break;
			case R.id.settings:
				Intent i = new Intent(this, SettingsActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(i);
				break;
			case R.id.about:
				makeDialog();
				break;	
			case R.id.exit:
				finish();
				//System.exit(0);
				break;
		}
		
	}
	
	private void makeDialog() {		
		
	    AlertDialog.Builder dialog = new AlertDialog.Builder(this);	    
	    
	    dialog.setMessage("This is a demo");

	    dialog.setPositiveButton("Buy the full version", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface arg0, int arg1) {
	        	Toast.makeText(getBaseContext(), "BUY IT", Toast.LENGTH_LONG).show();
	        }
	    });
	
	    dialog.setNegativeButton("Close", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface arg0, int arg1) {}
	    });
	
	    dialog.show();
	}
}
